package com.qianguo.buyer.api;

import android.support.v4.util.ArrayMap;

import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.Map;

/**
 * @author eva
 * @date 15/11/25
 */
public class RequestParams {

    private final ArrayMap<String, String> mMap;

    RequestParams(Builder builder) {
        mMap = builder.mParams;
    }

    public int size() {
        return mMap.size();
    }

    public String keyAt(int index) {
        return mMap.keyAt(index);
    }

    public String valueAt(int index) {
        return mMap.valueAt(index);
    }

    public String value(String key) {
        return mMap.get(key);
    }

    public static class Builder {

        private ArrayMap<String, String> mParams = null;

        public Builder() {
            mParams = new ArrayMap<>();
        }

        private Builder innerPut(String name, String value) {
            mParams.put(name, value);
            return this;
        }

        public Builder putParam(String name, String value) {
            return innerPut(name, value);
        }

        public Builder putParam(String name, int value) {
            return innerPut(name, Integer.toString(value));
        }

        public Builder putParam(String name, float value) {
            return putParam(name, value, 2);
        }

        public Builder putParam(String name, float value, int precision) {
            return putParam(name, String.format("%.0" + precision + "f", value));
        }

        public Builder putParam(String name, Date date) {
            return putParam(name, date, "yyyy-MM-dd HH:mm:ss");
        }

        public Builder putParam(String name, Date date, String format) {
            SimpleDateFormat df = (SimpleDateFormat) SimpleDateFormat.getInstance();
            df.applyPattern(format);
            return innerPut(name, df.format(date));
        }

        public RequestParams build() {
            return null;
        }
    }
}
